package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcRfidReaderGroupAlarmLightMapper;
import com.csun.cmny.provider.exceptions.DmcBizException;
import com.csun.cmny.provider.model.domain.DmcRfidReaderGroupAlarmLight;
import com.csun.cmny.provider.service.DmcRfidReaderGroupAlarmLightService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-08-22 15:04
 * @Description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DmcRfidReaderGroupAlarmLightServiceImpl extends BaseService<DmcRfidReaderGroupAlarmLight>
        implements DmcRfidReaderGroupAlarmLightService {

    @Resource
    private DmcRfidReaderGroupAlarmLightMapper dmcRfidReaderGroupAlarmLightMapper;

    /**
     * bind rfid reader group and alarm light
     *
     * @param dmcRfidReaderGroupAlarmLight the dmc rfid reader group alarm light
     * @return the int.
     */
    @Override
    public Integer bind(DmcRfidReaderGroupAlarmLight dmcRfidReaderGroupAlarmLight) {

        DmcRfidReaderGroupAlarmLight query = new DmcRfidReaderGroupAlarmLight();
        query.setRfidReaderGroupId(dmcRfidReaderGroupAlarmLight.getRfidReaderGroupId());
        int count = dmcRfidReaderGroupAlarmLightMapper.selectCount(query);
        if (count > 0) {
            // 门禁组已经绑定
            throw new DmcBizException(ErrorCodeEnum.DMC10064006);
        }

        query = new DmcRfidReaderGroupAlarmLight();
        query.setAlarmLightId(dmcRfidReaderGroupAlarmLight.getAlarmLightId());
        count = dmcRfidReaderGroupAlarmLightMapper.selectCount(query);
        if (count > 0) {
            // 报警灯已经绑定
            throw new DmcBizException(ErrorCodeEnum.DMC10062003);
        }

        return dmcRfidReaderGroupAlarmLightMapper.insertSelective(dmcRfidReaderGroupAlarmLight);
    }

    /**
     * untied rfid reader group and alarm light
     *
     * @param dmcRfidReaderGroupAlarmLight the dmc rfid reader group alarm light
     * @return the int.
     */
    @Override
    public Integer untied(DmcRfidReaderGroupAlarmLight dmcRfidReaderGroupAlarmLight) {

        return dmcRfidReaderGroupAlarmLightMapper.delete(dmcRfidReaderGroupAlarmLight);
    }
}
